/* poporcb7.p - CREATE PURCHASE ORDER HISTORY (FOR PO RECEIPT)                */
/* Copyright 1986 QAD Inc. All rights reserved.                               */
/* $Id:: poporcb7.p 86049 2019-05-20 09:51:07Z ksf                         $: */
/*                                                                            */
/* REVISION: 7.4     LAST MODIFIED: 03/16/95    BY: smp *F0N5*                */
/* REVISION: 7.4     LAST MODIFIED: 03/29/95    BY: dzn *F0PN*                */
/* REVISION: 7.4     LAST MODIFIED: 04/18/95    BY: dxk *G0KY*                */
/* REVISION: 8.5     LAST MODIFIED: 08/22/95    BY: tjs *J06Z*                */
/* REVISION: 8.5     LAST MODIFIED: 10/02/95    BY: vrn *G0Y8*                */
/* REVISION: 8.5     LAST MODIFIED: 11/09/95    BY: jym *G1BR*                */
/* REVISION: 8.5     LAST MODIFIED: 10/13/95    BY: taf *J053*                */
/* REVISION: 8.5     LAST MODIFIED: 02/05/96    BY: *J0CV* Robert Wachowicz   */
/* REVISION: 8.5     LAST MODIFIED: 09/10/96    BY: *G2DX* Sue Poland         */
/* REVISION: 8.5     LAST MODIFIED: 05/13/97    BY: *G2M4* Ajit Deodhar       */
/* REVISION: 8.5     LAST MODIFIED: 10/21/97    BY: *H1G5* Seema Varma        */
/* REVISION: 8.6E    LAST MODIFIED: 05/09/98    BY: *L00Y* Jeff Wootton       */
/* REVISION: 8.6E    LAST MODIFIED: 06/17/98    BY: *L020* Charles Yen        */
/* REVISION: 8.6E    LAST MODIFIED: 08/19/98    BY: *L062* Steve Nugent       */
/* REVISION: 8.6E    LAST MODIFIED: 09/02/98    BY: *H1N0* Seema Varma        */
/* REVISION: 8.6E    LAST MODIFIED: 09/15/98    BY: *K1WX* Steve Nugent       */
/* REVISION: 9.0     LAST MODIFIED: 01/05/99    BY: *M04C* Steve Nugent       */
/* REVISION: 9.0     LAST MODIFIED: 03/13/99    BY: *M0BD* Alfred Tan         */
/* REVISION: 9.0     LAST MODIFIED: 03/15/99    BY: *M0BG* Jeff Wootton       */
/* REVISION: 9.0     LAST MODIFIED: 04/16/99    BY: *J2DG* Reetu Kapoor       */
/* REVISION: 9.1     LAST MODIFIED: 10/01/99    BY: *N014* PATTI GAULTNEY     */
/* REVISION: 9.1     LAST MODIFIED: 03/24/00    BY: *N08T* Annasaheb Rahane   */
/* REVISION: 8.6     LAST MODIFIED: 05/04/00    BY: *K25Y* Patrick Rowan      */
/* REVISION: 9.1     LAST MODIFIED: 06/08/00    BY: *M0ND* Reetu Kapoor       */
/* REVISION: 9.1     LAST MODIFIED: 08/13/00    BY: *N0KQ* Mark Brown         */
/* REVISION: 9.1     LAST MODIFIED: 10/04/00    BY: *M0SQ* Santosh Rao        */
/* REVISION: 9.1     LAST MODIFIED: 01/12/01    BY: *N0VL* Manish Kulkarni    */
/* Revision: 1.30     BY: Katie Hilbert           DATE: 04/01/01  ECO: *P002* */
/* Revision: 1.31     BY: Katie Hilbert           DATE: 04/17/01  ECO: *P00P* */
/* Revision: 1.35     BY: Steve Nugent            DATE: 04/17/02  ECO: *P043* */
/* Revision: 1.36     BY: Patrick Rowan           DATE: 05/24/02  ECO: *P018* */
/* Revision: 1.37     BY: Luke Pokic              DATE: 05/24/02  ECO: *P03Z* */
/* Revision: 1.38     BY: Jean Miller             DATE: 06/06/02  ECO: *P080* */
/* Revision: 1.39     BY: Patrick Rowan           DATE: 06/19/02  ECO: *P091* */
/* Revision: 1.41     BY: Robin McCarthy          DATE: 07/15/02  ECO: *P0BJ* */
/* Revision: 1.43     BY: Andrea Suchankova       DATE: 06/24/02  ECO: *N14J* */
/* Revision: 1.44     BY: Katie Hilbert           DATE: 01/06/03  ECO: *P0LN* */
/* Revision: 1.46     BY: Pawel Grzybowski        DATE: 03/27/03  ECO: *P0NT* */
/* Revision: 1.48     BY: Paul Donnelly (SB)      DATE: 06/28/03  ECO: *Q00J* */
/* Revision: 1.49     BY: Sandy Brown (OID)       DATE: 12/06/03  ECO: *Q04L* */
/* Revision: 1.53     BY: SurenderSingh Nihalani  DATE: 10/26/04  ECO: *P2R9* */
/* Revision: 1.54     BY: Anil Sudhakaran         DATE: 09/14/05  ECO: *P2PJ* */
/* Revision: 1.55     BY: Steve Nugent            DATE: 12/01/05  ECO: *R000* */
/* Revision: 1.56     BY: Shivaraman V.           DATE: 01/12/06  ECO: *P4FV* */
/* Revision: 1.57     BY: Cindy Votro             DATE: 03/21/06  ECO: *R001* */
/* Revision: 1.58     BY: Robin McCarthy          DATE: 06/15/06  ECO: *R04H* */
/* Revision: 1.61     BY: Steve Nugent            DATE: 07/31/06  ECO: *P4JR* */
/* Revision: 1.62     BY: Jean Miller             DATE: 07/07/08  ECO: *R0W4* */
/* Revision: 1.63     BY: Prashant Menezes        DATE: 09/11/08  ECO: *P6R3* */
/* Revision: 1.64     BY: Denzel Paul             DATE: 05/21/09  ECO: *Q2WX* */
/* Revision: 1.66     BY: Katie Hilbert           DATE: 04/12/10  ECO: *R1ZG* */
/* Revision: 1.67     BY: Miguel Alonso           DATE: 05/07/10 ECO: *R204*  */
/* Revision: 1.68     BY: Yiqing Chen             DATE: 04/08/10  ECO: *R1Z0* */
/*-Revision end---------------------------------------------------------------*/
 
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
 
{us/bbi/mfdeclre.i}
{us/gp/gpoidfcn.i}  /* Defines nextOidValue() function */
{us/bbi/gplabel.i}    /* EXTERNAL LABEL INCLUDE */
{us/ap/apconsdf.i}   /* PRE-PROCESSOR CONSTANTS FOR LOGISTICS ACCOUNTING */
 
{us/rc/rcwabsdf.i new}
 
{us/po/popvodet.i}   /* pvod_det TEMP-TABLE */
 
/* PROGRAM X-REFERENCE FUNCTIONS */
{us/wh/whexecfn.i}
{us/px/pxmaint.i}
{us/px/pxphdef.i popoxr1}
{us/px/pxphdef.i gpldxr}
{us/ic/icshtxut.i}   /* Common procedures for inventory movment tax */
 
 
/* INPUT PARAMETERS */
define input        parameter  pod_recno   as   recid no-undo.
define input        parameter  ship_date   like prh_ship_date no-undo.
define input        parameter  po_recno    as   recid no-undo.
define input        parameter  sct_recno   as   recid no-undo.
define input        parameter  rcv_type    like poc_rcv_type no-undo.
define input        parameter  site        like pod_site no-undo.
define input        parameter  is-return   like mfc_logical no-undo.
define input        parameter  eff_date    like glt_effdate no-undo.
define input        parameter  vendlot     like prh_vend_lot no-undo.
define input        parameter  receivernbr like prh_receiver no-undo.
define input        parameter  ps_nbr      like prh_ps_nbr no-undo.
define input        parameter  dr_acct     like trgl_dr_acct no-undo.
define input        parameter  dr_sub      like trgl_dr_sub no-undo.
define input        parameter  dr_cc       like trgl_dr_cc no-undo.
define input        parameter  project     like pvo_project no-undo.
define input        parameter  price       like tr_price no-undo.
define input        parameter  exch_rate   like exr_rate no-undo.
define input        parameter  exch_rate2  like exr_rate no-undo.
define input        parameter  exch_ratetype like exr_ratetype no-undo.
define input        parameter  exch_exru_seq like exru_seq no-undo.
define input        parameter  yes_char    as   character
   format "x(1)" no-undo.
define input        parameter  i_shipto    like abs_mstr.abs_shipto no-undo.
define input-output parameter  crtint_amt  like trgl_gl_amt no-undo.
define input        parameter  use_pod_um_conv as logical no-undo.
define input        parameter  consigned_flag as logical no-undo.
define input        parameter  p_shipper_rec  as logical no-undo.
define input        parameter  p_int_ref_type like lacd_internal_ref_type   no-undo.
define input        parameter  p_abs_um       as character no-undo.
define input        parameter  p_abs_um_conv  as decimal   no-undo.
define input        parameter  p_abs_um_qty   as decimal   no-undo.
define input-output parameter  stdcst      like tr_price no-undo.
 
define      shared  variable   rndmthd     like rnd_rnd_mthd.
 
define      shared  variable   lgdkey      like lgd_mstr.oid_lgd_mstr no-undo.
define      shared  variable   issueld     as logical no-undo.
 
define new  shared  variable   qopen       like pod_qty_rcvd no-undo.
define new  shared  variable   qty_ord     like pod_qty_ord no-undo.
define new  shared  variable   qty_diff    like pod_qty_rcvd no-undo.
define new  shared  variable   pod_recid   as recid no-undo.
  
define      shared  workfile   tax_wkfl
   field      tax_nbr     like pod_nbr
   field      tax_line    like pod_line
   field      tax_env     like pod_tax_env
   field      tax_usage   like pod_tax_usage
   field      tax_taxc    like pod_taxc
   field      tax_in      like pod_tax_in
   field      tax_taxable like pod_taxable
   field      tax_price   like prh_pur_cost.
  
define variable     line_amt        like trgl_gl_amt.
define variable     schtype         like sch_type initial 4 no-undo.
define variable     l_adg_862       like mfc_logical no-undo.
define variable     rcpt_tr_type    like tx2d_det.tx2d_tr_type no-undo.
define variable     l_glxcst        like glxcst no-undo.
define variable     mc-error-number like msg_nbr no-undo.
define variable     use-log-acctg    as logical               no-undo.
define variable     auto_subship_update   as logical  no-undo.
define variable     supplier_perf_enabled as logical  no-undo.
 
/* Pending Voucher variables*/
define variable proc_id          as character no-undo.
define variable line-nbr         as integer   no-undo.
define variable pvod_det_proc_id as character no-undo.
define variable lc_ers_opt       like pod_ers_opt no-undo.
define variable vlApplyTax       as logical   no-undo.
define temp-table tt_pvo_mstr no-undo like pvo_mstr
   index pvo_id pvo_domain pvo_id.
define buffer bf_abs_mstr for abs_mstr.
define variable l_POUnloading as logical no-undo.
  
l_POUnloading = false.
publish "POUnloading" (output l_POUnloading).

for first poc_ctrl no-lock
   where poc_domain = global_domain:
end.
 
/**  DOWN GRADED TO A NO-LOCK SEE NO REASON FOR SHARE-LOCK **/
for first po_mstr where recid(po_mstr) = po_recno
no-lock: end.
 
/**  DOWN GRADED TO A NO-LOCK SEE NO REASON FOR SHARE-LOCK **/
for first pod_det where recid(pod_det) = pod_recno
no-lock: end.
 
for first sct_det where recid(sct_det) = sct_recno
no-lock: end.
 
for first icc_ctrl where icc_ctrl.icc_domain = global_domain
no-lock: end.
 
 
/* For PO Returns, we need to get the shipper associated. It is possible */
/* to update Tax parameters during PO Returns if the Transaction Type    */
/* (ISS-PRV) is defined in GTM Control file (29.24). It is necessary to  */
/* use the Tax parameters (Tax usage, Tax Environment etc) entered at    */
/* PO Returns rather than PO Maintenance.                                */
 
assign
   vlApplyTax = no.
 
/* This is the child abs record */
for first abs_mstr where abs_domain    = global_domain and
                         abs_order     = pod_nbr       and 
                         int(abs_line) = pod_line 
no-lock:
 
   /* Get the parent abs_mstr to get the Inventory Movement Code */
   for first bf_abs_mstr 
      where bf_abs_mstr.abs_domain = global_domain and
            bf_abs_mstr.abs_shipfrom = abs_mstr.abs_shipfrom and
            bf_abs_mstr.abs_id = abs_mstr.abs_par_id 
   no-lock:
      for first im_mstr where im_domain  = global_domain
                          and im_inv_mov = bf_abs_mstr.abs_inv_mov 
      no-lock:
         if im_tr_type = "ISS-PRV" then 
            /* Check if Tax parameters are editable */
            vlApplyTax = WhetherApplyTax(input bf_abs_mstr.abs_inv_mov).
      end.
   end.
end.
 
/* SET AUTO UPDATE VARIABLE FOR SUBCONTRACT SHIPPING */
if c-application-mode = "API" then
   auto_subship_update = yes.
else do:
   for first scs_ctrl no-lock where
      scs_domain = global_domain:
 
   if scs_enter_shipper = false
   then
      auto_subship_update = yes.
   else
      auto_subship_update = no.
   end.
end.
 
if stdcst = 0 and available sct_det then
   stdcst = sct_cst_tot.
 
/* CALCULATING STDCST FOR ATO/KIT ITEMS FOR AN EMT PO TO REFLECT   */
/* ENTIRE CONFIGURATION COST AND CREATE PRH_HIST WITH CORRECT COST */
if po_is_btb
   and can-find(first pt_mstr where pt_mstr.pt_domain = global_domain
                and pt_part    = pod_part
                and pt_pm_code = "c")
then do:
   run p-price-configuration.
   stdcst = stdcst + l_glxcst.
end. /* IF PO_IS_BTB AND ... */
 
/* CREATE PURCHASE RECEIPT HISTORY RECORD */
create prh_hist.
prh_hist.prh_domain = global_domain.
 
if rcv_type = 0 then
   prh_print = no.
 
if pod_taxable then
   prh_tax_at = "yes".
else
   prh_tax_at = "".
 
/* WHEN PO IS RAISED IN STOCKING UM AND RECEIVED IN ALTERNATE UM;   */
/* CONVERT THE QUANTITY RECEIVED BY DIVIDING WITH CONVERSION FACTOR */
/* TO AVOID ROUNDING ERRORS. */
 
if use_pod_um_conv
then do:
   if p_shipper_rec
   then do:
      if is-return
      then
         prh_rcvd = (- pod_qty_chg).
      else do:
         if pod_um = p_abs_um
         then
            prh_rcvd = pod_qty_chg.
         else do:
            if not l_POUnloading
            then 
               prh_rcvd = p_abs_um_qty.
            else
               prh_rcvd = (pod_qty_chg * pod_um_conv) / p_abs_um_conv .
         end.
      end. /* IF NOT is-return */
   end. /* IF p_shipper_rec */
   else
      prh_rcvd = (if is-return then (- pod_qty_chg)
                  else pod_qty_chg) / pod_um_conv.
end. /* IF use_pod_um_conv */
else
   prh_rcvd = (if is-return then (- pod_qty_chg)
               else pod_qty_chg) * pod_rum_conv.

assign
   prh_site            = site
   prh_part            = pod_part
   prh_nbr             = pod_nbr
   prh_line            = pod_line
   prh_cum_rcvd        = pod_cum_qty[1] + prh_rcvd
   prh_curr_rlse_id[1] = pod_curr_rlse_id[1]
   prh_rcp_date        = eff_date
   prh_vend_lot        = vendlot
   prh_vend            = po_vend
   prh_receiver        = receivernbr
   prh_lot             = pod_wo_lot
   prh_ps_nbr          = ps_nbr
   prh_ps_qty          = pod_ps_chg * (if is-return then pod_rum_conv else 1)
   prh_bo_qty          = pod_bo_chg
   prh_po_site         = pod_po_site
   prh_pur_std         = stdcst
   prh_sub_std         = (if pod_type = "s" then stdcst else 0)
   prh_rev             = pod_rev
   prh_type            = pod_type
   prh_buyer           = po_buyer
   prh_cst_up          = pod_cst_up
   prh_um              = p_abs_um
   prh_um_conv         = p_abs_um_conv
   prh_pur_cost        = price
   prh_fix_pr          = pod_fix_pr
   prh_crt_int         = pod_crt_int
   prh_curr            = po_curr
   prh_per_date        = if pod_per_date <> ?
                         then
                            pod_per_date
                         else
                            today
   prh_qty_ord         = pod_qty_ord
   prh_ship            = po_ship
   prh_request         = pod_request
   prh_curr_amt        = prh_pur_cost
   prh_approve         = pod_approve
   prh_rma_type        = pod_rma_type
   prh_fsm_type        = pod_fsm_type
   prh_ship_date       = ship_date
   prh_shipto          = i_shipto when (i_shipto <> po_vend)
   prh_ex_rate         = exch_rate
   prh_ex_rate2        = exch_rate2
   prh_ex_ratetype     = exch_ratetype
   prh_hist.oid_lgd_mstr = lgdkey
   prh_fix_rate          = po_fix_rate.
   
if issueld then do:
   /* Update asscociated and cancelled LD reference in receiver */
   {us/px/pxrun.i &PROC = 'updateReceiverLDReference'
      &PROGRAM = 'gpldxr.p'
      &handle  = ph_gpldxr
      &PARAM   = "(input lgdkey)"
      &NOAPPERROR = true
      &CATCHERROR = true}
end.

/* FISCAL CONFIRM ENABLED */
if available poc_ctrl and poc_fiscal_confirm then do:
   {us/px/pxrun.i &PROC = 'updateFiscalLineForPO'
      &PROGRAM = 'gpldxr.p'
      &handle  = ph_gpldxr
      &PARAM   = "(input lgdkey,
                   buffer prh_hist)"
      &NOAPPERROR = true
      &CATCHERROR = true}
end.
 
if available abs_mstr and vlApplyTax 
then do:
   /* If Tax parameters are edited during PO Returns, they should be  */
   /* considered rather than from the original PO                     */
   assign
      prh_taxc            = abs_mstr.abs_taxc
      prh_tax_env         = abs_mstr.abs_tax_env
      prh_tax_in          = abs_mstr.abs_tax_in
      prh_tax_usage       = abs_mstr.abs_tax_usage.
end.
else do:
   /* If Tax parameters are not edited during PO Returns, they should be  */
   /* considered from the original PO                                     */
   assign
      prh_taxc            = pod_taxc
      prh_tax_env         = pod_tax_env
      prh_tax_in          = pod_tax_in
      prh_tax_usage       = pod_tax_usage.
end.
 
/* CREATE A PENDING VOUCHER RECORD*/
/* BY POPULATING A TEMP-TABLE AND */
/* CALLING APPVROP.P TO CREATE THE PHYSICAL RECORD.*/
 
for each tt_pvo_mstr where tt_pvo_mstr.pvo_domain = global_domain
exclusive-lock:
   delete tt_pvo_mstr.
end.
 
create tt_pvo_mstr.
 
assign
   tt_pvo_mstr.oid_pvo_mstr = nextOidValue()
   tt_pvo_mstr.pvo_domain = global_domain
   tt_pvo_mstr.pvo_id                    = 0
   tt_pvo_mstr.pvo_supplier              = prh_vend
   tt_pvo_mstr.pvo_internal_ref_type     = {&TYPE_POReceiver}
   tt_pvo_mstr.pvo_internal_ref          = receivernbr
   tt_pvo_mstr.pvo_external_ref          = prh_ps_nbr
   tt_pvo_mstr.pvo_trans_date            = prh_rcp_date
   tt_pvo_mstr.pvo_eff_date              = eff_date
   tt_pvo_mstr.pvo_cost_update           = prh_cst_up
   tt_pvo_mstr.pvo_part                  = prh_part
   tt_pvo_mstr.pvo_shipto                = prh_site
   tt_pvo_mstr.pvo_trans_qty             = prh_rcvd
   tt_pvo_mstr.pvo_vouchered_qty         = 0
   tt_pvo_mstr.pvo_vouchered_amt         = 0
   tt_pvo_mstr.pvo_accrued_amt           = 0
   tt_pvo_mstr.pvo_curr                  = prh_curr
   tt_pvo_mstr.pvo_order                 = pod_nbr
   tt_pvo_mstr.pvo_line                  = pod_line
   tt_pvo_mstr.pvo_order_type            = {&TYPE_PO}
   tt_pvo_mstr.pvo_ers_status            = 0
   tt_pvo_mstr.pvo_mod_userid            = global_userid
   tt_pvo_mstr.pvo_mod_date              = today
   tt_pvo_mstr.pvo_accrual_acct          = dr_acct
   tt_pvo_mstr.pvo_accrual_sub           = dr_sub
   tt_pvo_mstr.pvo_accrual_cc            = dr_cc
   tt_pvo_mstr.pvo_project               = project
   tt_pvo_mstr.pvo_buyer                 = prh_buyer
   tt_pvo_mstr.pvo_approve               = prh_approve
   tt_pvo_mstr.pvo_consignment           = no
   proc_id                               = "create".
 
if available abs_mstr and vlApplyTax 
then do:
   /* If Tax parameters are edited during PO Returns, they should be  */
   /* considered rather than from the original PO                     */
   assign
       tt_pvo_mstr.pvo_taxable   = abs_mstr.abs_taxable
       tt_pvo_mstr.pvo_taxc      = abs_mstr.abs_taxc
       tt_pvo_mstr.pvo_tax_env   = abs_mstr.abs_tax_env
       tt_pvo_mstr.pvo_tax_in    = abs_mstr.abs_tax_in
       tt_pvo_mstr.pvo_tax_usage = abs_mstr.abs_tax_usage.
end.
else do:
   /* If Tax parameters are not edited during PO Returns, they should be  */
   /* considered from the original PO                                     */
   assign
      tt_pvo_mstr.pvo_taxable               = pod_taxable
      tt_pvo_mstr.pvo_taxc                  = pod_taxc
      tt_pvo_mstr.pvo_tax_env               = pod_tax_env
      tt_pvo_mstr.pvo_tax_in                = pod_tax_in
      tt_pvo_mstr.pvo_tax_usage             = pod_tax_usage.
end.
 
if recid(tt_pvo_mstr) = -1 then.
 
for first lgd_mstr no-lock where
    lgd_mstr.lgd_domain = global_domain and
    lgd_mstr.oid_lgd_mstr = lgdkey:
 
    assign 
       lc_ers_opt = pod_det.pod_ers_opt
       tt_pvo_mstr.pvo_ers_opt = lc_ers_opt.
 
   {us/gp/gprunp.i "soldxr" "p" "DateFormatToYMD"}
 
   tt_pvo_mstr.pvo_external_ref = lgd_mstr.lgd_nbr + "," + string(lgd_mstr.lgd_effdate).
   {us/gp/gprunp.i "soldxr" "p" "RevertDateFormat"}    
end. 
 
find first  tax_wkfl
   where tax_nbr  = pod_nbr
   and   tax_line = pod_line no-lock no-error.
 
if available tax_wkfl then 
assign
   tt_pvo_mstr.pvo_taxc      = tax_wkfl.tax_taxc
   tt_pvo_mstr.pvo_tax_env   = tax_wkfl.tax_env
   tt_pvo_mstr.pvo_tax_in    = tax_wkfl.tax_in
   tt_pvo_mstr.pvo_tax_usage = tax_wkfl.tax_usage
   prh_pur_cost              = tax_wkfl.tax_price / pod_um_conv.
 
/* CREATE A PENDING VOUCHER DETAIL RECORD BY POPULATING A TEMP-TABLE AND */
/* CALLING APPVDROP.P TO CREATE THE PHYSICAL RECORD.*/
for each tt_pvoddet exclusive-lock:
   delete tt_pvoddet.
end.
 
create tt_pvoddet.
assign
   pvoddet_internal_ref_type    = tt_pvo_mstr.pvo_internal_ref_type
   pvoddet_internal_ref         = tt_pvo_mstr.pvo_internal_ref
   pvoddet_cost_update          = tt_pvo_mstr.pvo_cost_update
   pvoddet_part                 = tt_pvo_mstr.pvo_part
   pvoddet_shipto               = tt_pvo_mstr.pvo_shipto
   pvoddet_order                = tt_pvo_mstr.pvo_order
   pvoddet_line                 = tt_pvo_mstr.pvo_line
   pvoddet_order_type           = tt_pvo_mstr.pvo_order_type
   pvoddet_mod_userid           = tt_pvo_mstr.pvo_mod_userid
   pvoddet_mod_date             = tt_pvo_mstr.pvo_mod_date
   pvoddet_accrual_acct         = tt_pvo_mstr.pvo_accrual_acct
   pvoddet_accrual_sub          = tt_pvo_mstr.pvo_accrual_sub
   pvoddet_accrual_cc           = tt_pvo_mstr.pvo_accrual_cc
   pvoddet_project              = tt_pvo_mstr.pvo_project
   pvoddet_taxable              = tt_pvo_mstr.pvo_taxable
   pvoddet_taxc                 = tt_pvo_mstr.pvo_taxc
   pvoddet_tax_env              = tt_pvo_mstr.pvo_tax_env
   pvoddet_tax_in               = tt_pvo_mstr.pvo_tax_in
   pvoddet_tax_usage            = tt_pvo_mstr.pvo_tax_usage
   pvoddet_vouchered_amt        = 0
   pvoddet_accrued_amt          = tt_pvo_mstr.pvo_accrued_amt
   pvoddet_eff_date             = eff_date
   pvoddet_trans_date           = today
   pvoddet_trans_qty            = tt_pvo_mstr.pvo_trans_qty
   pvoddet_ex_rate              = exch_rate
   pvoddet_ex_rate2             = exch_rate2
   pvoddet_ex_ratetype          = exch_ratetype
   pvoddet_vouchered_qty        = 0
   pvoddet_pur_cost             = prh_pur_cost
   pvoddet_pur_std              = prh_pur_std.

/* UPDATE tt_pvoddet WITH MATERIAL LABOUR BURDEN AND SUBCONTRACT COSTS */
if available sct_det and pod_type = ""
then do:
   if icc_cogs
   then
   assign
      pvoddet_mtl_std = (sct_mtl_tl + sct_mtl_ll
      + sct_lbr_ll + sct_bdn_ll
      + sct_ovh_ll + sct_sub_ll)
      pvoddet_lbr_std = sct_lbr_tl
      pvoddet_bdn_std = sct_bdn_tl
      pvoddet_sub_std = sct_sub_tl.
   else
   assign
      pvoddet_mtl_std = sct_mtl_tl + sct_mtl_ll + l_glxcst
      pvoddet_lbr_std = sct_lbr_tl + sct_lbr_ll
      pvoddet_bdn_std = sct_bdn_tl + sct_bdn_ll
      pvoddet_sub_std = sct_sub_tl + sct_sub_ll.
end. /* IF AVAILABLE sct_det */
 
/* CONVERT THE PO COST TO BASE CURRENCY IF FOREIGN CURRENCY PO */
if prh_curr <> base_curr then do:
   {us/gp/gprunp.i "mcpl" "p" "mc-curr-conv"
      "(input prh_curr,
        input base_curr,
        input pvoddet_ex_rate,
        input pvoddet_ex_rate2,
        input pvoddet_pur_cost,
        input false, /* DO NOT ROUND */
        output pvoddet_pur_cost,
        output mc-error-number)"}.
end.
  
if recid(tt_pvoddet) = -1 then.
 
if available sct_det and pod_type = "" then do:
   if icc_cogs then
      pvoddet_ovh_std = sct_ovh_tl.
   else
      pvoddet_ovh_std = sct_ovh_tl + sct_ovh_ll.
end.
/* IF NOT A CONSIGNED LINE ITEM THEN CREATE A PENDING VOUCHER */
if not consigned_flag and
   (not poc_fiscal_confirm
    or issueld = yes)
then do:
 
   /* CREATE A PENDING VOUCHER PHYSICAL RECORD*/
   {us/bbi/gprun.i ""appvorop.p""
      "(input proc_id,
        input-output table tt_pvo_mstr)"}
 
   for first tt_pvo_mstr no-lock:
      pvoddet_id = tt_pvo_mstr.pvo_id.
   end.
 
   /* SET PROCEDURE ID */
   pvod_det_proc_id = "read-last".
 
   /* DETERMINE LAST pvod_det LINE FOR A pvo_mstr */
   {us/bbi/gprun.i ""appvdrop.p""
      "(input pvod_det_proc_id,
        input-output table tt_pvoddet,
        output line-nbr)"}
 
   /* ASSIGN NEXT LINE NUMBER */
   line-nbr = line-nbr + 1.
 
   for first tt_pvoddet exclusive-lock:
      pvoddet_id_line = line-nbr.
   end.
 
   /* SET PROCEDURE ID */
   pvod_det_proc_id = "create".
 
   /* CREATE A PENDING VOUCHER DETAIL RECORD */
   {us/bbi/gprun.i ""appvdrop.p""
      "(input pvod_det_proc_id,
        input-output table tt_pvoddet,
        output line-nbr)"}
end.  /* if not consigned_flag */
 
/*READ THE PENDING VOUCHER TEMP TABLE RECORD AGAIN*/
for first tt_pvo_mstr where tt_pvo_mstr.pvo_domain = global_domain
no-lock: end.
 
/* READ THE PENDING VOUCHER DETAIL RECORD AGAIN */
for first tt_pvoddet no-lock:
end.
 
if is-return then
assign
   prh_rcp_type = "R"
   prh_reason = pod_reason.
 
/* For RTS's assign the receipt type to  */
/* "R" signifying an Return to Supplier. */
if pod_fsm_type <> "" then
   assign prh_rcp_type = "R".
 
/* UPDATE TAX INFORMATION IF FISCAL RECEIVING */
 
/* ACCUMULATE CREDIT TERMS INTEREST */
if pod_crt_int <> 0 then do:
   /* PRICE IS UNIT PRICE IN DOCUMENT CURRENCY */
   line_amt = prh_rcvd * price.
   /* ROUND PER DOCUMENT CURRENCY ROUND METHOD */
   {us/gp/gprunp.i "mcpl" "p" "mc-curr-rnd"
      "(input-output line_amt,
        input rndmthd,
        output mc-error-number)"}
 
   crtint_amt = crtint_amt +
      (line_amt - (line_amt / ((pod_crt_int + 100) / 100))).
   /* ROUND PER DOCUMENT CURRENCY ROUND METHOD */
   {us/gp/gprunp.i "mcpl" "p" "mc-curr-rnd"
      "(input-output crtint_amt,
        input rndmthd,
        output mc-error-number)"}
end.
 
/* VALIDATE IF LOGISTICS ACCOUNTING IS TURNED ON */
{us/bbi/gprun.i ""lactrl.p"" "(output use-log-acctg)"}
 
if (use-log-acctg
   and po_tot_terms_code <> ""
   and pod_type           = "")
   and poc_ctrl.poc_fiscal_confirm = no
   and not is-return
then do:
   /* FOR EACH LOGISTICS ACCOUNTING CHARGE */
   /* APPLICABLE TO THE LINE */
   /* CREATE NEW PVOD_DET RECORD */
   /* IF PVO_MSTR RECORD DOES NOT EXIST FOR THIS CHARGE, CREATE IT */
   {us/gp/gprunmo.i &module = "LA" &program = ""lapochrg.p""
      &param  = """(buffer po_mstr,
        buffer pod_det,
        buffer prh_hist,
        input p_int_ref_type)"""}
end. /* IF (use-log-acctg AND.... */
 
if pod_sched then do:
 
   /* CHECK FLAG TO SEE IF ADG 862 MODULE IS INSTALLED */
   /* AND ACTIVATED                                    */
   {us/bbi/gprun.i ""gpmfc01.p""
      "(input 'enable_shipping_schedules',
        input '',
        input 'ADG',
        input '',
        output l_adg_862)"}
 
   if l_adg_862 or po_trade_sale then do:
 
      for first schd_det where schd_det.schd_domain = global_domain and
         schd_type = 6          and
         schd_nbr = pod_nbr     and
         schd_line = pod_line   and
         schd_rlse_id = pod_curr_rlse_id[3]
      no-lock: end.
 
      if available schd_det then
         schtype = 6.
      else do:
 
         for first schd_det where schd_det.schd_domain = global_domain and
            schd_type = 5         and
            schd_nbr  = pod_nbr   and
            schd_line = pod_line  and
            schd_rlse_id = pod_curr_rlse_id[2]
         no-lock:
            schtype = 5.
         end. /* for first schd_det */
 
      end. /* else do: */
 
   end. /* if l_adg_862 then do */
 
   for last schd_det where schd_det.schd_domain = global_domain
      and schd_type = schtype
      and schd_nbr  = pod_nbr
      and schd_line = pod_line
      and schd_rlse_id = pod_curr_rlse_id[schtype - 3]
      and schd_date <= eff_date
   no-lock:
      prh_cum_req = schd_cum_qty.
   end.
 
   assign
      prh_qty_ord  = 0
      prh_per_date = ?.
 
   for first sch_mstr where sch_mstr.sch_domain = global_domain
      and sch_type = schtype
      and sch_nbr = pod_nbr
      and sch_line = pod_line
      and sch_rlse_id = pod_curr_rlse_id[schtype - 3]
   no-lock: end.
 
   if available sch_mstr then do:
      prh_per_date = sch_pcs_date.
 
      if sch_pcr_qty > pod_cum_qty[1] 
      then
         prh_qty_ord = sch_pcr_qty - pod_cum_qty[1].
 
      else do:
 
         for first schd_det where schd_det.schd_domain = global_domain and
            schd_type = schtype  and
            schd_nbr  = pod_nbr  and
            schd_line = pod_line and
            schd_rlse_id = pod_curr_rlse_id[schtype - 3] and
            schd_cum_qty > pod_cum_qty[1]
         no-lock: end.
 
         if available schd_det then
         assign
            prh_per_date = schd_date
            prh_qty_ord = schd_cum_qty - pod_cum_qty[1].
 
         else do:
 
            for last schd_det where schd_det.schd_domain = global_domain and
               schd_type = schtype  and
               schd_nbr = pod_nbr   and
               schd_line = pod_line and
               schd_rlse_id = pod_curr_rlse_id[schtype - 3]
            no-lock:
               assign
                  prh_per_date = schd_date
                  prh_qty_ord = 0.
            end.
 
         end.
      end.   /* else do */
   end.  /* if available sch_mstr then do: */
 
   /* QTY OPEN IS NOT USED IN SUPPLIER SCHEDULES BUT IS NEEDED
      FOR SUPPLIER PERFORMANCE CALCULATIONS. SO FOR SCHEDULES
      only WE WILL SET THE SHARED VARIABLE qopen EQUAL TO
      prh_qty_ord. THIS WILL NOT AFFECT SUPPLIER SCHEDULE
      FUNCTIONALITY SINCE qopen IS NOT USED, BUT IT WILL ALLOW
      SUPPLIER PERFORMANCE TO GATHER INFORMATION ON SUPPLIER
      SCHEDULE RECEIPTS */
 
   qty_ord = prh_cum_req - pod_cum_qty[1].
 
   if qty_ord < 0 then
      qty_ord = 0.
 
   /* CHANGED REFERENCE FROM schd_det TO sch_mstr */
   if available sch_mstr then
      qopen = prh_qty_ord.
 
   else 
   assign
      qopen = pod_qty_ord - pod_qty_rcvd
      qty_ord = prh_rcvd.
 
   /* IF prh_rcvd IS GREATER THAN qopen THEN WE WANT TO STORE
      THAT QTY DIFFERENCE IN VARIABLE qty_diff SO THAT WE CAN
      USE IT IN porcvea.p TO APPLY AGAINST THE NEXT DATE IN THE
      SUPPLIER SCHEDULE AND RECORD SUPPLIER PERFORMANCE EVENTS
      IF NEED BE */
 
   if qopen <> 0 and qopen < prh_rcvd then
      qty_diff = prh_rcvd - qopen.
   else
      qty_diff = 0.
 
   pod_recid = pod_recno.
 
end.  /* if pod_sched then do: */
 
if not pod_sched then do:
 
   assign
      pod_recid = pod_recno
      qty_ord   = prh_qty_ord
      qopen     = pod_qty_ord - pod_qty_rcvd.
 
   if qopen < 0 then
      qopen = 0.
 
 
end. /* if not pod_sched then do: */
 
/*  IF PURCHASE ORDER IS SUBCONTRACT AND THE USER DID NOT MANUALLY */
/*  ASSOCIATE SUBCONTRACT SHIPPERS TO THIS RECEIPT, THEN UPDATE    */
/*  SUB SHIPPER RECORDS AUTOMATICALLY WITH THE QTY RECEIVED.       */
if pod_type = "s" and
   auto_subship_update = yes
then do:
   {us/bbi/gprun.i ""porcssup.p""
      "(input po_vend,
        input pod_wo_lot,
        input prh_rcvd,
        input eff_date,
        input site)"}
end.
 
/* QAD WAREHOUSING MODULE: USING RADIO FREQUENCY DEVICES, SYSTEM MUST SKIP */
/* SUPPLIER PERFORMANCE MODULE AS THIS INFORMATION IS NOT ENTERED BY USERS */
/* IN THE WAREHOUSE.                                                       */
if not isProgInStack("whexexs.p")
then do:
 
   /* DETERMINE IF SUPPLIER PERFORMANCE IS INSTALLED */
   /* CHANGED CALLED PROGRAM TO porcvea.p. porcve.p IS OBSOLETE */
   {us/bbi/gprun.i ""gpmfc01.p""
      "(input 'enable_supplier_perf',
        input '',
        input '',
        input 'vef_ctrl',
        output supplier_perf_enabled)"}

   if supplier_perf_enabled
   then do:
      {us/bbi/gprun.i ""porcvea.p""
         "(input recid(prh_hist))"}
   end. /* if enable supplier performance */
end.
 
if prh_curr <> base_curr and
poc_ctrl.poc_fiscal_confirm = no 
then do:
 
/* CONVERT FROM FOREIGN TO BASE CURRENCY */
{us/gp/gprunp.i "mcpl" "p" "mc-curr-conv"
   "(input prh_curr,
     input base_curr,
     input pvoddet_ex_rate,
     input pvoddet_ex_rate2,
     input prh_pur_cost,
     input false, /* DO NOT ROUND */
     output prh_pur_cost,
     output mc-error-number)"}.
end.
 
/* GET STANDARD COSTS FOR THIS LEVEL USING SCT_DET RECORD */
if available sct_det and pod_type  = "" then do:
   if icc_cogs then
   assign
      prh_mtl_std = sct_mtl_tl + sct_mtl_ll
                  + sct_lbr_ll + sct_bdn_ll
                  + sct_ovh_ll + sct_sub_ll
      prh_lbr_std = sct_lbr_tl
      prh_bdn_std = sct_bdn_tl
      prh_ovh_std = sct_ovh_tl
      prh_sub_std = sct_sub_tl.
   else
   assign
      prh_mtl_std = sct_mtl_tl + sct_mtl_ll + l_glxcst
      prh_lbr_std = sct_lbr_tl + sct_lbr_ll
      prh_bdn_std = sct_bdn_tl + sct_bdn_ll
      prh_ovh_std = sct_ovh_tl + sct_ovh_ll
      prh_sub_std = sct_sub_tl + sct_sub_ll.
end. /* if available sct_det and... then do */
 
 
PROCEDURE p-price-configuration:
   /* PROCEDURE TO OBTAIN COST OF COMPONENT ITEMS FOR AN EMT PO */
 
   define variable l_qty_req like sob_qty_req no-undo.
 
   l_glxcst = 0.
 
   for first sod_det where sod_det.sod_domain = global_domain
      and sod_nbr  = po_mstr.po_so_nbr
      and sod_line = pod_det.pod_sod_line
      and sod_compl_stat = ""
   no-lock: end.
 
   if available sod_det then do:
 
      for each sob_det where sob_det.sob_domain = global_domain
                         and sob_nbr  = sod_nbr
                         and sob_line = sod_line
      no-lock
      break by sob_part:
 
         if first-of(sob_part) then
            l_qty_req = 0.
 
         if substring(sob_serial,15,1) = "o" then
            l_qty_req = l_qty_req + sob_qty_req.
 
         if last-of(sob_part) and
            l_qty_req <> 0
         then do:
            {us/bbi/gprun.i ""gpsct05.p""
               "(input sob_part, sob_site, input 1,
                 output glxcst, output curcst)"}
            glxcst = glxcst * (sob_qty_req / sod_qty_ord).
            l_glxcst = l_glxcst + glxcst.
         end. /* IF LAST-OF (SOB_PART) ... */
 
      end. /* FOR EACH SOB_DET */
 
   end. /* IF AVAILABLE SOD_DET */
 
end. /* PROCEDURE P-PRICE-CONFIGURATION */
